package com.inews.business.entity;

public class PageIndex {
	
	private long pageSize;
	private long startindex;
	private long endindex;
	private long currentPage;
	private long totalPage;
	
	
	public PageIndex(long pageSize, long startindex, long endindex,
			long currentPage, long totalPage) {
		super();
		this.pageSize = pageSize;
		this.startindex = startindex;
		this.endindex = endindex;
		this.currentPage = currentPage;
		this.totalPage = totalPage;
	}
	
	public long getStartindex() {
		return startindex;
	}
	public void setStartindex(long startindex) {
		this.startindex = startindex;
	}
	public long getEndindex() {
		return endindex;
	}
	public void setEndindex(long endindex) {
		this.endindex = endindex;
	}
	public long getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(long currentPage) {
		this.currentPage = currentPage;
	}

	public long getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
	}
	
	public long getPagesize() {
		return pageSize;
	}
	
	public long getPageSize() {
		return pageSize;
	}
	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}
	
	public static PageIndex getPageIndex(int currentPage, long totalPage){
			long pageSize = 10;
			long startpage = currentPage-(pageSize%2==0? pageSize/2-1 : pageSize/2);
			long endpage = currentPage+pageSize/2;
			if(startpage<1){
				startpage = 1;
				if(totalPage>=pageSize) endpage = pageSize;
				else endpage = totalPage;
			}
			if(endpage>totalPage){
				endpage = totalPage;
				if((endpage-pageSize)>0) startpage = endpage-pageSize+1;
				else startpage = 1;
			}
			return new PageIndex(pageSize, startpage, endpage, currentPage, totalPage);		
	}
}